// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var router = require("../hash/pageRouter");
	var css_tallyDetail = require("./bulkstockTallyDetail.css");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var constant = require("constant");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var imgSrc;
	var recieveNoticeId;
	var tallyingId;
	var inventoryId;
	var type;
	var taskDetail;
	var init = function(page) {
		recieveNoticeId = page.params.recieveNoticeId || base.getUrlParam("recieveNoticeId");
		tallyingId = page.params.tallyingId || base.getUrlParam("tallyingId");
		inventoryId = page.params.inventoryId || base.getUrlParam("inventoryId");
		if (inventoryId != null && inventoryId.length >= 0) {
			inquireBulkstockInventoryDetail(inventoryId);
		} else {
		}
		type = page.params.type || base.getUrlParam("type");
		type = "readOnly";

		initEvent();
		router.init();

		$("#leftMenu1").find(".leftMenu-item").removeClass("leftMenu-active");
		$("#leftMenu1 #newTaskList").parent(".leftMenu-item").addClass("leftMenu-active");
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}

	};


	//查询融资箱货明细
	var inquireBulkstockInventoryDetail = function(inventoryId) {
		base.fnAjax({
			action: "inquireBulkstockInventoryDetail.json",
			oData: {
				inventoryId: inventoryId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#tallyDetailTpl").html();
					var html = juicer(tpl, data);
					$(".tallyDetail_main_content").html(html);
					$.each($(".bulkstockFilesUuids"), function(i, val) {
						showImg($(this).parent().find(".uploadImgP"), val.value);
					});
					$.each($(".suffixTallyFiles"), function(i, val) {
						showImg($(this).parent(), val.value);
					});
					$.each($(".preTallyFiles"), function(i, val) {
						showImg($(this).parent(), val.value);
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}

		//显示图片
	var showImg = function(dom, fileUuid) {
		var fileUuids = fileUuid.split(",");
		var html = "";
		var imgSrc = "";
		for (var i = 0; i < fileUuids.length; i++) {
			imgSrc = fileUuids[i];
			if (imgSrc.length != 0) {
				html = "<label class=\"finance-file\"><img  src=\"/finance/api/1.0/downloadFile.file?fileUuid=" + imgSrc + "\" class=\"finance-field-img\"  alt=\"" + imgSrc + "\"  /> <a class=\"closeLayer\" ></a></label>";
				$(dom).append(html);
			}

		}
	}

	return {
		init: init
	};
});